﻿Imports System.Data.OleDb

Public Class AddBook
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Btn_add_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Btn_add.Click
        Dim myGUID = Guid.NewGuid()
        Dim newFileName As String = myGUID.ToString() & ".jpg"
        If f_picture.HasFile Then
            Dim fileLocationOnServerHardDisk = Request.MapPath("pictures") & "/" & newFileName
            f_picture.SaveAs(fileLocationOnServerHardDisk)
        End If
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("booksConn").ConnectionString)
        Dim SqlString As String = "Insert into books(BookName,Author,YearPublished,Series,Picture,Description,MainCharacters,Pages,WikipediaPage,Traveller) Values (@f1,@f2,@f3,@f4,@f5,@f6,@f8,@f9,@f10,@f11)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", TB_BookName.Text)
        cmd.Parameters.AddWithValue("@f2", TB_Author.Text)
        cmd.Parameters.AddWithValue("@f3", TB_Year.Text)
        cmd.Parameters.AddWithValue("@f4", TB_Series.Text)
        cmd.Parameters.AddWithValue("@f5", "pictures/" & newFileName)
        cmd.Parameters.AddWithValue("@f6", TB_Desc.Text)
        cmd.Parameters.AddWithValue("@f8", TB_MainCh.Text)
        cmd.Parameters.AddWithValue("@f9", Int32.Parse(TB_Pages.Text))
        cmd.Parameters.AddWithValue("@f10", TB_WikiLink.Text)
        cmd.Parameters.AddWithValue("@f10", User.Identity.Name)
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        Response.Redirect("confirmation.aspx")
        oleDbConn.Close()

    End Sub

End Class